<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <!-- <el-form-item label="报表名称" prop="rptName">
        <el-input
          v-model="queryParams.rptName"
          placeholder="请输入报表名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="记录时间" prop="rptTime">
        <el-date-picker
          :editable="false"
          clearable
          size="small"
          v-model="queryParams.rptTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <!--  <el-form-item label="瓶坯供应商" prop="ppgys">
        <el-input
          v-model="queryParams.ppgys"
          placeholder="请输入瓶坯供应商"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="瓶盖供应商" prop="pggys">
        <el-input
          v-model="queryParams.pggys"
          placeholder="请输入瓶盖供应商"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="开机前排水检验杂质" prop="beforezj">
        <el-input
          v-model="queryParams.beforezj"
          placeholder="请输入开机前排水检验杂质"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开机检验杂质" prop="afterzj">
        <el-input
          v-model="queryParams.afterzj"
          placeholder="请输入开机检验杂质"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开机前对在线自动检测设备校准" prop="beforetest">
        <el-input
          v-model="queryParams.beforetest"
          placeholder="请输入开机前对在线自动检测设备校准"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="之后每4小时再校准一次" prop="fater4hour">
        <el-input
          v-model="queryParams.fater4hour"
          placeholder="请输入之后每4小时再校准一次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原物料不合格瓶坯" prop="unqualityp">
        <el-input
          v-model="queryParams.unqualityp"
          placeholder="请输入原物料不合格瓶坯"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="瓶盖" prop="unqualityg">
        <el-input
          v-model="queryParams.unqualityg"
          placeholder="请输入瓶盖"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="审核人" prop="auditor">
        <el-input
          v-model="queryParams.auditor"
          placeholder="请输入审核人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作人" prop="operator">
        <UserDialog
          @dialogChange="queryParams.operator = $event.label"
          :echoValue="queryParams.operator"
          :multiple="false"
          placeholder="请选择人员"
        />
        <!--  <el-input
          v-model="queryParams.operator"
          placeholder="请输入操作人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        /> -->
        <!-- <el-select
          v-model="queryParams.operator"
          filterable
          allow-create
          placeholder="请选择操作人"
          style="width: 100%"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in userList"
            :key="item.nickName"
            :label="item.nickName"
            :value="item.nickName"
          ></el-option>
        </el-select>-->
      </el-form-item>
      <!--  <el-form-item label="报表编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入报表编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工厂名称" prop="factory">
        <el-input
          v-model="queryParams.factory"
          placeholder="请输入工厂名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类型" prop="rptType">
        <el-select v-model="queryParams.rptType" placeholder="请选择设备类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['productionProcess:semifinished:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['productionProcess:semifinished:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['productionProcess:semifinished:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['productionProcess:semifinished:export']"
          >导出</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-s-check"
          size="mini"
          :disabled="multiple"
          @click="handleCheck"
          v-hasPermi="['productionProcess:semifinished:check']"
          >审核</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="semifinishedList"
      @selection-change="handleSelectionChange"
      max-height="500"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" width="80px" />
      <!--  <el-table-column label="报表名称" align="center" prop="rptName" /> -->
      <el-table-column
        label="记录时间"
        align="center"
        prop="rptTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rptTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="瓶坯供应商" align="center" prop="ppgysname" />
      <el-table-column label="瓶盖供应商" align="center" prop="pggysname" /> -->
      <!--  <el-table-column label="开机前排水检验杂质" align="center" prop="beforezj" />
      <el-table-column label="开机检验杂质" align="center" prop="afterzj" />
      <el-table-column label="开机前对在线自动检测设备校准" align="center" prop="beforetest" />
      <el-table-column label="之后每4小时再校准一次" align="center" prop="fater4hour" />
      <el-table-column label="原物料不合格瓶坯" align="center" prop="unqualityp" />
      <el-table-column label="瓶盖" align="center" prop="unqualityg" /> -->
      <el-table-column
        label="报表编码"
        align="center"
        prop="code"
        min-width="120px"
      />
      <el-table-column
        label="工厂名称"
        align="center"
        prop="factory"
        min-width="120px"
      />
      <el-table-column label="设备类型" align="center" prop="rptType" />
      <el-table-column label="操作人" align="center" prop="operator" />
      <el-table-column label="审核人" align="center" prop="auditor" />
      <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="250px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="excelhandleView(scope.row)"
            >导出</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['productionProcess:semifinished:edit']"
          >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['productionProcess:semifinished:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改生产线半成品检验记录对话框 -->
    <el-dialog
      fullscreen
      :title="title"
      :visible.sync="open"
      width="700px"
      append-to-body
      custom-class="myDialog"
    >
      <TableHeader
        @nameChange="nameChange"
        @nameChange2="nameChange2"
        :data="{
          mainTitle: '生产线半成品检验记录',
          company: form.factory,
          code: form.code,
        }"
      />
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <!-- <el-col :span="12">
                <el-form-item label="报表名称" prop="rptName">
                  <el-input v-model="form.rptName" placeholder="请输入报表名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <el-col :span="8">
            <el-form-item label="记录时间" prop="rptTime">
              <el-date-picker
                :editable="false"
                clearable
                size="small"
                v-model="form.rptTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择记录时间"
                :disabled="openDisabled"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="瓶坯供应商" prop="ppgys">
              <!-- <el-input
                v-model="form.ppgys"
                placeholder="请输入瓶坯供应商"
                :disabled="openDisabled"
              /> -->
              <!-- <Dialog
                @dialogChange="dialogChangeFactory($event)"
                :echoValue="form.ppgysname"
                parameter="rows"
                value="id"
                label="name"
                :multiple="true"
                search="name/code"
                url="/basic/eqpfactory/list"
                :column="['产成品编号/code', '产成品名称/name']"
                placeholder="请选择内容"
              /> -->
              <!-- <treeselect :searchable="false"
                v-model="form.ppgys"
                :options="deptOptions2"
                zIndex="9999"
                :appendToBody="true"
                :normalizer="normalizer2"
                placeholder="请选择设备厂家"
              /> -->
              <!-- <ReportDialog
                @dialogChange="form.ppgys = $event.value"
                :echoValue="form.ppgys"
                value="id"
                label="label"
                placeholder="选择设备厂家"
                :openDisabled="openDisabled"
              /> -->

              <treeselect
                v-model="form.pcjArray"
                :disable-branch-nodes="true"
                :options="dialogData"
                :limit="2"
                placeholder="选择设备厂家"
                :normalizer="normalizer3"
                :searchable="false"
                :appendToBody="false"
                multiple
                @select="addSelect"
                :disabled="openDisabled"
                collapse-tags
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="瓶盖供应商" prop="pggys">
              <!-- <el-input
                v-model="form.pggys"
                placeholder="请输入瓶盖供应商"
                :disabled="openDisabled"
              /> --><!-- <treeselect :searchable="false"
                v-model="form.pggys"
                :options="deptOptions2"
                zIndex="9999"
                :appendToBody="true"
                :normalizer="normalizer2"
                placeholder="请选择设备厂家"
              /> -->
              <!-- <ReportDialog
                @dialogChange="form.pggys = $event.value"
                :echoValue="form.pggys"
                value="id"
                label="label"
                placeholder="选择设备厂家"
                :openDisabled="openDisabled"
              /> -->

              <treeselect
                v-model="form.gcjArray"
                :disable-branch-nodes="true"
                :options="dialogData"
                :limit="2"
                placeholder="选择设备厂家"
                :normalizer="normalizer3"
                :searchable="false"
                :appendToBody="false"
                multiple
                @select="addSelect"
                :disabled="openDisabled"
                collapse-tags
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
                <el-form-item label="报表编码" prop="code">
                  <el-input v-model="form.code" placeholder="请输入报表编码" :disabled="openDisabled" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="工厂名称" prop="factory">
                  <el-input v-model="form.factory" placeholder="请输入工厂名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="设备类型" prop="rptType">
                  <el-select v-model="form.rptType" placeholder="请选择设备类型" :disabled="openDisabled">
                    <el-option label="请选择字典生成" value="" />
                  </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
        </el-row>

        <!-- 生产线半成品检验记录信息 -->
        <br />
        <el-divider content-position="center"
          >生产线半成品检验记录信息</el-divider
        >
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddRptProSemifinished"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteRptProSemifinished"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="semtotal"
              :disabled="openDisabled"
              >统计</el-button
            >
          </el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-table
          :data="rptProSemifinishedList"
          :row-class-name="rowRptProSemifinishedIndex"
          @selection-change="handleRptProSemifinishedSelectionChange"
          ref="rptProSemifinished"
          max-height="500"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          />
          <el-table-column label="开始时间" prop="kssj" width="160">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                clearable
                v-model="scope.row.kssj"
                value-format="HH:mm"
                format="HH:mm"
                placeholder="选择开始时间"
                :disabled="openDisabled"
              >
              </el-time-picker>
            </template>
          </el-table-column>
          <el-table-column label="结束时间" prop="jssj" width="160">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                clearable
                v-model="scope.row.jssj"
                value-format="HH:mm"
                format="HH:mm"
                placeholder="选择结束时间"
                :disabled="openDisabled"
              >
              </el-time-picker>
            </template>
          </el-table-column>
          <el-table-column label="全部成品名称" prop="gg" minWidth="320">
            <template slot-scope="scope">
              <!-- <el-input
                v-model="scope.row.cpmc"
                placeholder="请输入产品名称"
                :disabled="openDisabled"
              /> -->
              <Dialog
                @dialogChange="dialogChange($event, scope)"
                :echoValue="scope.row.ggname"
                parameter="rows"
                value="id"
                label="name"
                :multiple="false"
                search="name/code"
                url="/basic/productInfo/listSelect"
                :column="['产成品编号/code', '产成品名称/name']"
                placeholder="请选择全部成品"
                :axiosData="{ typeCode: 'YYTRKQS' }"
                :openDisabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="水质检验">
            <el-table-column label="杂质数量" prop="zzsl" minWidth="160">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.zzsl"
                  placeholder="请输入杂质数量"
                  :disabled="openDisabled"
                  type="number"
                />
              </template>
            </el-table-column>
            <el-table-column label="责任人" prop="zrnperson" minWidth="160">
              <template slot-scope="scope">
                <!-- <el-input
                  v-model="scope.row.zrnperson"
                  placeholder="请输入责任人"
                  :disabled="openDisabled"
                /> -->
                <el-select
                  v-model="scope.row.zrnperson"
                  placeholder="请选择责任人"
                  style="width: 100%"
                  :disabled="openDisabled"
                >
                  <el-option
                    v-for="item in userList"
                    :key="item.nickName"
                    :label="item.nickName"
                    :value="item.nickName"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>
          </el-table-column>

          <el-table-column label="标、码检验">
            <el-table-column label="验码人" prop="ymrperson" minWidth="160">
              <template slot-scope="scope">
                <!-- <el-input
                  v-model="scope.row.ymrperson"
                  placeholder="请输入验码人"
                  :disabled="openDisabled"
                /> -->
                <el-select
                  v-model="scope.row.ymrperson"
                  placeholder="请选择验码人"
                  style="width: 100%"
                  :disabled="openDisabled"
                >
                  <el-option
                    v-for="item in userList"
                    :key="item.nickName"
                    :label="item.nickName"
                    :value="item.nickName"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>
          </el-table-column>

          <el-table-column label="PET瓶检验">
            <el-table-column label="缺陷类型" prop="qxlx1" minWidth="200">
              <template slot-scope="scope">
                <!-- <el-input
                  v-model="scope.row.qxlx1"
                  placeholder="请输入缺陷类型"
                  :disabled="openDisabled"
                /> -->
                <treeselect
                  :searchable="false"
                  v-model="scope.row.qxlx1"
                  :options="deptOptions"
                  :normalizer="normalizer"
                  zIndex="9999"
                  :appendToBody="true"
                  placeholder="请选择缺陷类型"
                  :disabled="openDisabled"
                />
              </template>
            </el-table-column>
            <el-table-column label="数量" prop="sl1" minWidth="160">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.sl1"
                  placeholder="请输入数量"
                  type="number"
                  :disabled="openDisabled"
                />
              </template>
            </el-table-column>
          </el-table-column>

          <el-table-column label="瓶盖检验">
            <el-table-column label="缺陷类型" prop="qxlx2" minWidth="200">
              <template slot-scope="scope">
                <!-- <el-input
                  v-model="scope.row.qxlx2"
                  placeholder="请输入缺陷类型"
                  :disabled="openDisabled"
                /> -->
                <!-- <el-select
                  v-model="scope.row.qxlx2"
                  placeholder="请选择产品名称"
                  style="width: 100%"
                  :disabled="openDisabled"
                >
                  <el-option
                    v-for="dict in report_semifinished_qxlx"
                    :key="dict.index"
                    :label="dict.dictLabel"
                    :value="dict.dictLabel"
                  ></el-option>
                </el-select> -->
                <treeselect
                  :searchable="false"
                  v-model="scope.row.qxlx2"
                  :options="deptOptions"
                  :normalizer="normalizer"
                  zIndex="9999"
                  :appendToBody="true"
                  placeholder="请选择缺陷类型"
                  :disabled="openDisabled"
                />
              </template>
            </el-table-column>
            <el-table-column label="数量" prop="sl2" minWidth="160">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.sl2"
                  placeholder="请输入数量"
                  :disabled="openDisabled"
                  type="number"
                />
              </template>
            </el-table-column>
            <el-table-column label="统计人" prop="tjrperson" minWidth="160">
              <template slot-scope="scope">
                <!-- <el-input
                  v-model="scope.row.tjrperson"
                  placeholder="请输入统计人"
                  :disabled="openDisabled"
                /> -->
                <el-select
                  v-model="scope.row.tjrperson"
                  placeholder="请选择统计人"
                  style="width: 100%"
                >
                  <el-option
                    v-for="item in userList"
                    :key="item.nickName"
                    :label="item.nickName"
                    :value="item.nickName"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column label="异常说明" prop="ycsm" minWidth="200">
            <template slot-scope="scope">
              <el-input
                type="textarea"
                v-model="scope.row.ycsm"
                placeholder="请输入异常说明"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <!-- <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
                <el-input v-model="scope.row.remark" type="textarea" placeholder="请输入内容" :disabled="openDisabled"/>
            </template>
          </el-table-column> -->
        </el-table>

        <!-- 合计 -->
        <el-divider content-position="center"></el-divider>
        <el-table
          :data="rptProTotalList"
          :row-class-name="rowRptProTotalIndex"
          max-height="500"
        >
          <!-- <el-table-column type="selection" minWidth="50" align="center" /> -->
          <el-table-column
            label="序号"
            align="center"
            prop="index"
            minWidth="50"
          />
          <el-table-column label="类别" prop="cplxhj">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.remark"
                placeholder="请输入类别"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="产品" prop="cplxhj">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.cplxhj"
                placeholder="请输入产品名称"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>

          <!-- <el-table-column label="PET瓶数量"> -->
          <el-table-column label="设备缺陷" prop="sbqxjh1">
            <template slot-scope="scope">
              <!-- <el-input
                  v-model="scope.row.sbqxjh1"
                  placeholder="请输入设备缺陷"
                  :disabled="openDisabled"
                /> -->
              <treeselect
                :searchable="false"
                v-model="scope.row.sbqxjh1"
                :options="deptOptions"
                :normalizer="normalizer"
                zIndex="9999"
                :appendToBody="true"
                placeholder="请选择缺陷类型"
                :disabled="openDisabled"
                @select="myvalue1(scope, $event)"
              />
            </template>
          </el-table-column>
          <el-table-column label="质量缺陷" prop="zlqxjh1">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.zlqxjh1"
                placeholder="请输入数量"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <!-- </el-table-column> -->
        </el-table>

        <el-row>
          <el-col :span="12">
            <el-form-item
              label="开机前排水检验杂质（瓶）"
              prop="beforezj"
              label-width="210px"
            >
              <el-input
                v-model="form.beforezj"
                placeholder="请输入开机前排水检验杂质（瓶）"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="开机检验杂质（瓶）"
              prop="afterzj"
              label-width="180px"
            >
              <el-input
                v-model="form.afterzj"
                placeholder="请输入开机检验杂质"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="开机前对在线自动检测设备校准"
              prop="beforetest"
              label-width="210px"
            >
              <!-- <el-input
                v-model="form.beforetest"
                placeholder="请输入开机前对在线自动检测设备校准"
                :disabled="openDisabled"
              /> -->
              <el-select v-model="form.beforetest" :disabled="openDisabled">
                <el-option value="是">是</el-option>
                <el-option value="否">否</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="之后每4小时再校准一次"
              prop="fater4hour"
              label-width="180px"
            >
              <!-- <el-input
                v-model="form.fater4hour"
                placeholder="请输入之后每4小时再校准一次"
                :disabled="openDisabled"
              /> -->
              <el-select v-model="form.fater4hour" :disabled="openDisabled">
                <el-option value="是">是</el-option>
                <el-option value="否">否</el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="原物料不合格瓶坯"
              prop="unqualityp"
              label-width="210px"
            >
              <el-input
                v-model="form.unqualityp"
                placeholder="请输入原物料不合格瓶坯"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="瓶盖" prop="unqualityg" label-width="180px">
              <el-input
                v-model="form.unqualityg"
                placeholder="请输入瓶盖"
                :disabled="openDisabled"
              />
            </el-form-item>
          </el-col>

          <!-- 审核 -->
          <el-col :span="12">
            <el-form-item label="审核人" prop="auditor">
              <el-input v-model="form.auditor" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="操作人" prop="operator">
              <UserDialog
                @dialogChange="form.operator = $event.label"
                :echoValue="form.operator"
                :multiple="false"
                :openDisabled="openDisabled"
                placeholder="请选择人员"
              />
              <!-- <el-input
                v-model="form.operator"
                placeholder="请输入操作人"
                :disabled="openDisabled"
              /> -->
              <!--<el-select
                v-model="form.operator"
                filterable
                allow-create
                placeholder="请选择操作人"
                style="width: 100%"
                :disabled="openDisabled"
              >
                <el-option
                  v-for="item in userList"
                  :key="item.nickName"
                  :label="item.nickName"
                  :value="item.nickName"
                ></el-option>
              </el-select>-->
              <el-divider content-position="center"></el-divider>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listSemifinished,
  getSemifinished,
  delSemifinished,
  addSemifinished,
  updateSemifinished,
  checkSemifinished,
  qxtj,
} from "@/api/report/process/semifinished";
import { getInfo } from "@/api/login";
import { listUser } from "@/api/system/user";
import { listDefecttype } from "@/api/basic/defecttype/defecttype";
import { listEqpfactory } from "@/api/basic/eqpfactory/eqpfactory";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

import { listSelect2 } from "@/api/report/process/label";

export default {
  name: "Semifinished",
  components: { Treeselect },
  data() {
    return {
      /* 当前用户名 */
      nickName: "",
      userList: [],
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      dialogData: [],
      // 缺陷树选项
      deptOptions: [],
      // 树选项
      deptOptions2: [],
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedRptProSemifinished: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产线半成品检验记录表格数据
      semifinishedList: [],
      // 生产线半成品检验记录子表格数据
      rptProSemifinishedList: [],
      // 合计数据
      rptProTotalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        rptName: null,
        rptTime: null,
        rptTime1: null,
        ppgys: null,
        pggys: null,
        beforezj: null,
        afterzj: null,
        beforetest: null,
        fater4hour: null,
        unqualityp: null,
        unqualityg: null,
        auditor: null,
        operator: null,
        code: null,
        factory: null,
        rptType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getListfac();
    this.getList();
    this.queryUserList();
  },
  methods: {
    /** 转换数据结构 */
    normalizer3(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.label,
        children: node.children,
      };
    },
    /** 转换数据结构 */
    normalizer2(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },
    addSelect(value) {
      console.log(value);
      // this.selectList = value.label
    },
    getListfac() {
      listSelect2().then((response) => {
        this.dialogData = response.rows;
        // console.log(response.rows)
        // // console.log(this.dialogData);
        // /*        this.selectionLabel = this.findPathByLeafId(
        //   this.echoValue,
        //   this.tableData
        // );*/
      });
    },
    myvalue1(scope, thisScope) {
      // console.log(scope);
      // console.log(thisScope);
      let nums = 0;
      this.rptProTotalList.forEach((item1) => {
        if (item1.cplxhj == scope.row.cplxhj) {
          item1.zlqxjh1 = 0;
          this.rptProSemifinishedList.forEach((item) => {
            if (
              item.qxlx1 == thisScope.defectId &&
              item.ggname == item1.cplxhj
            ) {
              item1.zlqxjh1 += parseInt(item.sl1);
            }
          });
        }
      });
      // console.log(nums);
    },
    myvalue2(scope, thisScope) {
      // console.log(scope);
      // console.log(thisScope);
      let nums = 0;
      this.rptProTotalList.forEach((item1) => {
        if (item1.cplxhj == scope.row.cplxhj) {
          item1.zlqxjh2 = 0;
          this.rptProSemifinishedList.forEach((item) => {
            if (
              item.qxlx2 == thisScope.defectId &&
              item.ggname == item1.cplxhj
            ) {
              item1.zlqxjh2 += parseInt(item.sl2);
            }
          });
        }
      });
      // console.log(nums);
    },
    dialogChange(event, scope) {
      // // console.log(scope);
      this.rptProSemifinishedList[scope.$index].gg = event.options.code;
      this.rptProSemifinishedList[scope.$index].ggname = event.label;
      // console.log(this.rptProArrangesub1List)
    },
    // 合计
    semtotal() {
      this.rptProTotalList = [];

      this.queryParams.rptTime = this.form.rptTime;
      qxtj(this.queryParams).then((response) => {
        //  console.log(response);
        response.forEach((item) => {
          let obj = {};
          obj.id = 0;
          obj.cplxhj = item.ggname;
          obj.sbqxjh1 = item.qxlx1;
          if (item.remark == "qx1") {
            obj.remark = "PET瓶检验";
          }
          if (item.remark == "qx2") {
            obj.remark = "瓶盖检验";
          }
          obj.zlqxjh1 = item.sl1;
          this.rptProTotalList.push(obj);
        });
      });
    },
    dialogChangeFactorypg(event) {
      this.form.pggys = event.value;
      this.form.pggysname = event.label;
    },
    dialogChangeFactory(event) {
      this.form.ppgys = event.value;
      this.form.ppgysname = event.label;
    },
    // 结束时间比开始时间多30分钟
    // triggerTime(scope) {
    //   let l = new Date("1900-10-10" + scope.row.kssj + ":00").getTime() + 1800000;
    //   // 时间戳格式工具
    //   let d = formatDate(l);
    //   this.rptProSemifinishedList[scope.$index].jssj = d;
    // },
    /** 查询生产线半成品检验记录列表 */
    getList() {
      this.loading = true;
      listSemifinished(this.queryParams).then((response) => {
        this.semifinishedList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rptName: null,
        rptTime: null,
        ppgys: null,
        ppgysname: null,
        pggys: null,
        pggysname: null,
        beforezj: null,
        afterzj: null,
        beforetest: null,
        fater4hour: null,
        unqualityp: null,
        unqualityg: null,
        auditor: null,
        operator: this.nickName,
        code: "LK-QF-LS1-10-007-11-01",
        factory: "青岛崂山矿泉水有限公司",
        rptType: "生产线半成品检验",
        delFlag: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.rptProSemifinishedList = [];
      this.resetForm("form");

      const myDate = new Date();
      const year = myDate.getFullYear();
      const month = myDate.getMonth() + 1;
      const day = myDate.getDate();
      this.form.rptTime = `${year}-${month}-${day}`;

      // 供应商  树状结构
      listEqpfactory().then((response) => {
        this.deptOptions2 = this.handleTree(response.data, "id");
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.rptTime != null) {
        let arr = this.queryParams.rptTime;
        this.queryParams.rptTime = arr[0];
        this.queryParams.rptTime1 = arr[1];
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.rptProTotalList = [];
      this.openDisabled = false;
      this.open = true;
      this.title = "添加生产线半成品检验记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      // 缺陷类型
      listDefecttype().then((response) => {
        this.deptOptions = this.handleTree(response.data, "defectId");
      });
      getSemifinished(id).then((response) => {
        this.form = response.data;
        this.rptProSemifinishedList = response.data.rptProSemifinishedList;
        this.open = true;
        this.title = "修改生产线半成品检验记录";
        // this.rptProTotalList = response.data.rptProSemifinishedTotalList;
        //合计
        this.semtotal();
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;
      const id = row.id || this.ids;
      // 缺陷类型
      listDefecttype().then((response) => {
        this.deptOptions = this.handleTree(response.data, "defectId");
      });

      getSemifinished(id).then((response) => {
        this.form = response.data;
        this.rptProSemifinishedList = response.data.rptProSemifinishedList;
        this.open = true;
        this.title = "查看生产线半成品检验记录";
        //合计
        // this.rptProTotalList = response.data.rptProSemifinishedTotalList;
        this.semtotal();
      });

      // this.semtotal();
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.rptProSemifinishedList = this.rptProSemifinishedList;
          this.form.rptProSemifinishedTotalList = this.rptProTotalList;
          if (this.form.id != null) {
            updateSemifinished(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            const rLoading = this.openLoading();
            addSemifinished(this.form)
              .then((response) => {
                this.msgSuccess("新增成功");
                this.open = false;
                rLoading.close();
                this.getList();
              })
              .catch((error) => {
                rLoading.close();
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除生产线半成品检验记录编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delSemifinished(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 生产线半成品检验记录子序号 */
    rowRptProSemifinishedIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 合计序号 */
    rowRptProTotalIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    addDate(time) {
      let rq = "";
      const arr = time.split(":");
      if (Number(arr[1]) < 30) {
        rq = arr[0] + ":" + (Number(arr[1]) + 30);
      } else {
        if (Number(arr[0]) <= 22) {
          rq = Number(arr[0]) + 1 + ":" + (Number(arr[1]) - 30);
        } else {
          rq = "00:" + (Number(arr[1]) - 30);
        }
      }
      return rq;
    },
    /** 生产线半成品检验记录子添加按钮操作 */
    handleAddRptProSemifinished() {
      // 时间递增 半个小时
      let l = this.rptProSemifinishedList.length;
      let krq = "";
      let jrq = "";
      if (l > 0 && this.rptProSemifinishedList[l - 1].kssj != "") {
        let time = this.rptProSemifinishedList[l - 1].kssj;
        krq = this.addDate(time);
      }
      if (l > 0 && this.rptProSemifinishedList[l - 1].jssj != "") {
        let time = this.rptProSemifinishedList[l - 1].jssj;
        jrq = this.addDate(time);
      }
      let obj = {};
      obj.kssj = krq;
      obj.jssj = jrq;
      obj.gg = "";
      obj.ggname = "";
      obj.zzsl = "";
      obj.zrnperson = "";
      obj.ymrperson = "";
      obj.qxlx1 = null;
      obj.sl1 = "";
      obj.qxlx2 = null;
      obj.sl2 = "";
      obj.tjrperson = "";
      obj.ycsm = "";
      obj.remark = "";
      this.rptProSemifinishedList.push(obj);

      // 缺陷类型
      listDefecttype().then((response) => {
        this.deptOptions = this.handleTree(response.data, "defectId");
      });
    },

    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.defectId,
        label: node.defectName,
        children: node.children,
      };
    },
    /** 生产线半成品检验记录子删除按钮操作 */
    handleDeleteRptProSemifinished() {
      if (this.checkedRptProSemifinished.length == 0) {
        this.$alert("请先选择要删除的生产线半成品检验记录子数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.rptProSemifinishedList.splice(
          this.checkedRptProSemifinished[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleRptProSemifinishedSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.rptProSemifinished.clearSelection();
        this.$refs.rptProSemifinished.toggleRowSelection(selection.pop());
      } else {
        this.checkedRptProSemifinished = selection;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "productionProcess/semifinished/export",
        {
          ...this.queryParams,
        },
        "生产线半成品检验记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    excelhandleView(row) {
      this.download(
        "Laboratory/semifinished/exportexcel?id=" + row.id,
        {
          ...this.queryParams,
        },
        "生产线半成品检验记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    //接收编号
    nameChange(e) {
      this.form.code = e;
    },
    nameChange2(e) {
      this.form.factory = e;
    },
    /** 审核按钮操作 */
    handleCheck(row) {
      /* 审核 */
      this.ids.forEach((id) => {
        getSemifinished(id).then((response) => {
          if (response.data.auditor != null && response.data.auditor != "") {
            this.msgError(
              '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
            );
          } else {
            let obj = {};
            obj.id = id;
            obj.auditor = this.nickName;
            obj.rptProSemifinishedList = this.rptProSemifinishedList;
            /* 修改 */
            checkSemifinished(obj).then((response) => {
              this.msgSuccess('编号为"' + id + '"的数据项审核成功！');
              this.getList();
            });
          }
        });
      });
    },
    /* 查询用户列表 */
    queryUserList() {
      listUser({ deptId: 101 }).then((response) => {
        this.userList = response.rows;
      });
      getInfo().then((response) => {
        this.nickName = response.user.nickName;
      });
    },
  },
};
</script>
